package com.quectel.core.module.application.dto;

import com.quectel.core.module.device.dto.DeviceTypeDto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.io.Serializable;
import java.util.Date;

/**
 * 应用配置模版表
 *
 * @author rananxin
 * @email: ryan.ran@quectel.com
 * @date 2021-11-09 09:48:18
 */
@Data
@Schema
public class ApplicationAccessTemplateDto implements Serializable {

    /**
     *
     */
    @Schema(description = "")
    private Long id;

    /**
     * 设备类型id
     */
    @Schema(description = "设备类型id")
    private Long deviceTypeId;

    /**
     * 接入方式id
     */
    @Schema(description = "接入方式id")
    private Long accessConfId;

    /**
     * 模版名称
     */
    @Schema(description = "模版名称")
    private String name;

    /**
     * 协议类型 0其他 1HTTP 2MQTT 3TCP
     */
    @Schema(description = "协议类型 0其他 1HTTP 2MQTT 3TCP")
    private Byte protocolType;

    /**
     * tcp服务端口
     */
    @Schema(description = "tcp服务端口")
    private Integer port;

    /**
     * 接入配置模版
     */
    @Schema(description = "接入配置模版")
    private String accessConf;

    /**
     * 定时任务支持 0否 1是
     */
    @Schema(description = "定时任务支持 0否 1是")
    private Byte taskEnable;

    /**
     * 定时任务间隔分钟
     */
    @Schema(description = "定时任务间隔分钟")
    private Integer taskInterval;

    /**
     * 备注
     */
    @Schema(description = "备注")
    private String remark;

    /**
     *
     */
    @Schema(description = "")
    private String creator;

    /**
     *
     */
    @Schema(description = "")
    private Date createTime;

    /**
     *
     */
    @Schema(description = "")
    private String editor;

    /**
     *
     */
    @Schema(description = "")
    private Date editTime;

    /************非数据库字段 start ************/

    @Schema(description = "设备类型信息")
    private DeviceTypeDto deviceType;

    @Schema(description = "接入方式")
    private ApplicationAccessConfDto applicationAccessConf;

    @AllArgsConstructor
    public enum protocolTypeEnum {
        OTHER((byte) 0),
        HTTP((byte) 1),
        MQTT((byte) 2),
        TCP((byte) 3);

        @Getter
        private Byte protocolType;

        public static protocolTypeEnum getByProtocolType(Byte protocolType) {
            for (protocolTypeEnum value : values()) {
                if (value.getProtocolType().equals(protocolType)) {
                    return value;
                }
            }
            return null;
        }
    }

    /************非数据库字段 end **************/
}
